const mutations = {
  setSwiperImages(state, data) {
    state.swiperImages = data;
  },
  setClassificationImages(state, data) {
    state.classificationImages = data;
  },
  setBoonImages(state, data) {
    state.boonImages = data;
  },
  setHotTypeImages(state, data) {
    state.hotTypeImages = data;
  },
  setGuessImages(state, data) {
    state.guessImages = data;
  },
  //分类页
  setChooseId(state, data) {
    state.chooseId = data;
  },
  setClassifyLeftData(state, data) {
    state.classifyLeftData = data;
  },


  setClassifyRTopBannerHead(state, data) {
    state.classifyRTopBannerHead = data;
  },
  setClassifyRTopImages(state, data) {
    state.classifyRTopImages = data;
  },

  setSort(state, data) {
    state.sort = data;
  },
  setClassifyRDownTitle(state, data) {
    state.classifyRDownTitle = data;
  },
  setClassifyRDownImages(state, data) {
    state.classifyRDownImages = data;
  },
  setSearchFrontword(state, data) {
    state.searchFrontword = data;
  },
  setSearchHotWord(state, data) {
    state.searchHotWord = data;
  },
  setDidSearchWord(state, data) {
    let index = state.didSearchWord.indexOf(data)
    if (index !== -1) {
      state.didSearchWord.splice(index, 1);
    }
    // state.searchNow=[data];
    state.didSearchWord.unshift(data);
  },
  clearDidSearchWord(state) {
    state.didSearchWord = [];
  },


  setIsShow(state, data) {
    state.isShow = data;
  },


  setGoodsTypes(state, data) {
    state.goodsTypes = data;
  },
  setGoodsList(state, data) {
    state.goodsList = data;
  },
  setGoodsSort(state, data) {
    state.goodsSort = data;
  },

  setGoodsDetail(state, data) {
    state.goodsDetail = data
  },
  setShoppingCart(state, {
    query,
    datas
  }) {
    let querys = {
      add(data) {
        // console.log(data);
        let key = state.shoppingCart[data.tradeItemId];
        if (key) {
          key.count++
        } else {
          state.shoppingCart[data.tradeItemId] = {
            count: 1,
            data
          }
        }
      },
      delete(data) {
        for (const key in data) {
          if (data[key]) {
            // console.log(key);
            delete(state.shoppingCart[key]);
          }
        }
      },
      edit(data) {
        debugger;
        // state.shoppingCart=JSON.parse(data);
        if (data.isAdd) {

          state.shoppingCart[data.i].count++;
          console.log(JSON.stringify(state.shoppingCart));
          //为了触发vue 动态更新
          state.shoppingCart=JSON.parse(JSON.stringify(state.shoppingCart));

        } else {
          if (state.shoppingCart[data.i].count > 1) {
          state.shoppingCart[data.i].count--;
          //为了触发vue 动态更新
          state.shoppingCart=JSON.parse(JSON.stringify(state.shoppingCart));
          }
        }
      }
    };
    querys[query](datas);

  },

  setGoodsCommentList(state, data) {
    state.goodsCommentList = data
  },


}
export default mutations
